function Fang = Fpotential(r_versor,ang_versor,fhandle,x,param)
% Fang = Fpotential_ang(r_versor,ang_versor,fhandle,x,param)
%
%
%k=param(1); % ??

Ns=size(r_versor,2); % number of segments
Fang=zeros(2,Ns+1);

f=repmat(feval(fhandle,x,param),2,1);

Fang(:,1) = f(:,1).*ang_versor(:,1);

Fang(:,2) = -f(:,1).*ang_versor(:,1) ...
            -f(:,1).*ang_versor(:,2) ...
            +f(:,2).*ang_versor(:,2);
% middle 
Fang(:,3:Ns-1) = f(:,1:Ns-3).*ang_versor(:,2:Ns-2) ...
                 -f(:,2:Ns-2).*ang_versor(:,2:Ns-2) ...
                 -f(:,2:Ns-2).*ang_versor(:,3:Ns-1) ...
                 +f(:,3:Ns-1).*ang_versor(:,3:Ns-1);

% Right most and second from the right
Fang(:,Ns) = f(:,Ns-2).*ang_versor(:,Ns-1) ...
			 -f(:,Ns-1).*ang_versor(:,Ns-1) ...
			 -f(:,Ns-1).*ang_versor(:,Ns); 

Fang(:,Ns+1) = f(:,Ns-1).*ang_versor(:,Ns);

% Left most and second from left
%Fang(:,1) = -k*dsin(1)*ang_versor(:,1);
%Fang(:,2) = k*( dsin(1)*ang_versor(:,1) + dsin(1)*ang_versor(:,2) - ...
%              dsin(2)*ang_versor(:,2) );
% middle 
%aux=repmat(dsin,2,1);
%Fang(:,3:Ns-1) = -k*( aux(:,1:Ns-3).*ang_versor(:,2:Ns-2) - ...
%                      aux(:,2:Ns-2).*ang_versor(:,2:Ns-2) - ...
%                      aux(:,2:Ns-2).*ang_versor(:,3:Ns-1) + ...
%                      aux(:,3:Ns-1).*ang_versor(:,3:Ns-1) );

% Right most and second from the right
%Fang(:,Ns) = -k*( dsin(Ns-2)*ang_versor(:,Ns-1) - ...
%                dsin(Ns-1)*ang_versor(:,Ns-1) - ...
%                dsin(Ns-1)*ang_versor(:,Ns) ); 
%Fang(:,Ns+1) = -k*dsin(Ns-1)*ang_versor(:,Ns);                

end
